﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace JMacia.Gaming.d20.Core.Traits
{
    public class Skill : Trait, ID20Modifier
    {
        #region Private Fields
        private bool _autoSucceed = false;
        private bool _autoFail = false;
        private Ability _keyAbility;
        private bool _trainedOnly = false;
        #endregion

        #region Public Static Readonly Fields
        public static readonly ModifierType[] StandardAllowedBonusTypes = new ModifierType[]{
            SystemModifierType.Ability,
            SystemModifierType.Alchemical,
            SystemModifierType.Circumstance,
            SystemModifierType.Competence,
            SystemModifierType.Insight,
            SystemModifierType.Luck,
            SystemModifierType.Morale,
            SystemModifierType.Profane,
            SystemModifierType.Racial,
            SystemModifierType.Sacred,
            SystemModifierType.Size,
            SystemModifierType.Synergy,
            SystemModifierType.Untyped};
        #endregion

        #region Constructors

        public Skill(string name, Ability keyAbility) : this(name, keyAbility, 0, new Modifiers(), StandardAllowedBonusTypes) { }

        public Skill(string name, Ability keyAbility, int ranks) : this(name, keyAbility, ranks, new Modifiers(), StandardAllowedBonusTypes) { }

        public Skill(string name, Ability keyAbility, int ranks, Modifiers modifiers) : this(name, keyAbility, ranks, modifiers, StandardAllowedBonusTypes) { }

        public Skill(string name, Ability keyAbility, int ranks,
            Modifiers modifiers, params ModifierType[] allowedBonusTypes)
            : base(name, ranks, modifiers, allowedBonusTypes)
        {
            KeyAbility = keyAbility;
        }

        #endregion

        #region Public Properties
        public int Ranks
        {
            get { return Base; }
            set { Base = value; }
        }
        public Ability KeyAbility
        {
            get { return _keyAbility; }
            set
            {
                if (_keyAbility != null)
                {
                    Modifiers.Remove(_keyAbility.Modifier);
                }
                _keyAbility = value;
                if (_keyAbility != null)
                {
                    Modifiers.Add(_keyAbility.Modifier);
                }
            }

        }
        public bool TrainedOnly
        {
            get { return _trainedOnly; }
            set { _trainedOnly = value; }
        }
        #endregion

        #region ID20Modifier Members
        /// <summary>
        /// Whether or not a roll of natural 20 for this skill automatically succeeds.
        /// </summary>
        public bool AutoSucceed
        {
            get
            {
                return _autoSucceed;
            }
            set
            {
                _autoSucceed = value;
            }
        }
        /// <summary>
        /// Whether or not a roll of natural 1 for this skill automatically fails.
        /// </summary>
        public bool AutoFail
        {
            get
            {
                return _autoFail;
            }
            set
            {
                _autoFail = value;
            }
        }

        #endregion
    }
}
